package userimage;

import userimage.page.Page;
import userimage.texteditor.TextEditor;

import javax.swing.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import static global.ProjectData.*;

public class WorkArea extends JPanel implements ComponentListener {

    //TODO 这里在开发期间有个默认的打开文件，功能全面后删除
    public static List<String> openFiles = new ArrayList<>();

    ToolsBar tb = new ToolsBar();
    Page texteditor = new Page(theme.toolsbar_width + theme.toolbarframe_width, 0, getWidth() - (theme.toolsbar_width + theme.toolbarframe_width), getHeight());


    EditorManager em = new EditorManager(texteditor, this);

    public WorkArea() throws FileNotFoundException {
        super();
        setBackground(theme.background);
        setLocation(0, theme.enumbar_height);
        setLayout(null);
        addComponentListener(this);

        //TODO 这里是加的默认打开文件
        openFiles.add("testfile");

        add(tb);
        add(texteditor);
        TextEditor te = new TextEditor(texteditor, openFiles.get(0));
        em.addEditor(te);
    }

    @Override
    public void componentResized(ComponentEvent componentEvent) {
        tb.setSize(tb.getWidth(), getHeight());

        texteditor.setLocation(theme.toolsbar_width + theme.toolbarframe_width, 0);
        texteditor.setSize(getWidth() - (theme.toolsbar_width + theme.toolbarframe_width), getHeight());
    }

    @Override
    public void componentMoved(ComponentEvent componentEvent) {

    }

    @Override
    public void componentShown(ComponentEvent componentEvent) {

    }

    @Override
    public void componentHidden(ComponentEvent componentEvent) {

    }
}
